package com.xiaofei.masterwork;

import java.util.Map;

public class Main {

	public static void main(String[] args) {
		Long start = System.currentTimeMillis();
		Master master = new Master(new Worker(), 1000);
		for(int i=1;i<100;i++){
			master.addTask(new Integer(i));
		}
		master.submit();
		Map<String, Object>resultMap = master.getResultMap();
		Integer result = 0;
		while(resultMap.size()>0||!master.isComplete()){
			for(Map.Entry<String, Object>entry:resultMap.entrySet()){
				result += (Integer)entry.getValue();
				resultMap.remove(entry.getKey());
			}
		}
		System.out.println(result);
		Long end = System.currentTimeMillis();
		System.out.println(end-start);
		start = System.currentTimeMillis();
		result = 0;
		for(int i=0;i<100;i++){
			result+=i*i;
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		end = System.currentTimeMillis();
		System.out.println(end-start);
	}

}
